package imnu.reflect;

import java.lang.reflect.Constructor;

/**
 * @author: lys
 * @类名: Test03
 * @Title:
 * @date: 2020/7/23
 **/
public class Test03 {
    public static void main(String[] args) {
        test01();
    }

    public static void test01() {
        try {
            //获取类文件对象
            Class type1=Class.forName("imnu.reflect.Student");
            //通过类文件对象创建构造函数对象
            Constructor cu= type1.getDeclaredConstructor(int.class,String.class,boolean.class);
            //通过构造函数对象实例化Student对象
            Student stu= (Student) cu.newInstance(25,"tom",true);
            //执行方法
            stu.sayBye("tom");
            stu.sayHi();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
